package com.huike.web.controller.business;

import com.huike.business.domain.TbBusiness;
import com.huike.business.service.BusinessService;
import com.huike.clues.domain.vo.AssignmentVo;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author STJ12138
 * @version 1.0
 * @description: TODO
 * @date 2023/7/12 15:00
 */
@RestController
@RequestMapping("/business")
@Api(tags = "商机相关接口")
@Slf4j
public class BusinessController {
    @Resource
    private BusinessService businessService;

    /**
     * @description: 新增商机
     * @param: tbBusiness
     * @return: com.huike.common.core.domain.AjaxResult<java.lang.Long>
     * @author STJ12138
     * @date: 2023/7/12 15:08
     */
    @PostMapping
    @ApiOperation("新增商机")
    public AjaxResult<Long> save(@RequestBody TbBusiness tbBusiness){
        Long id = businessService.add(tbBusiness);
        return AjaxResult.success(id);
    }

    /**
     * @description: 修改商机
     * @param: tbBusiness
     * @return: com.huike.common.core.domain.AjaxResult
     * @author STJ12138
     * @date: 2023/7/12 17:13
     */
    @PutMapping
    @ApiOperation("修改商机")
    public AjaxResult update(@RequestBody TbBusiness tbBusiness){
        businessService.update(tbBusiness);
        return AjaxResult.success();
    }

    /** 
     * @description: 商机分配 
     * @param: assignmentVo 
     * @return: com.huike.common.core.domain.AjaxResult 
     * @author STJ12138
     * @date: 2023/7/12 18:42
     */
    @PutMapping("/assignment")
    @ApiOperation("商机分配")
    public AjaxResult assignment(@RequestBody AssignmentVo assignmentVo){
        businessService.assignment(assignmentVo);
        return AjaxResult.success();
    }

    /** 
     * @description: 查询商机列表 
     * @param: tbBusiness 
     * @return: com.huike.common.core.page.TableDataInfo<java.util.List<com.huike.business.domain.TbBusiness>> 
     * @author STJ12138
     * @date: 2023/7/12 21:58
     */
    @GetMapping("/list")
    @ApiOperation("查询商机列表")
    public TableDataInfo<List<TbBusiness>> list(TbBusiness tbBusiness){
        TableDataInfo<List<TbBusiness>> tableDataInfo = businessService.list(tbBusiness);
        return tableDataInfo;
    }

    /**
     * @description: 获取商机详细信息
     * @param: id
     * @return: com.huike.common.core.domain.AjaxResult<com.huike.business.domain.TbBusiness>
     * @author STJ12138
     * @date: 2023/7/12 22:15
     */
    @GetMapping("/{id}")
    @ApiOperation("获取商机详细信息")
    public AjaxResult<TbBusiness> getById(@PathVariable Long id){
        TbBusiness tbBusiness = businessService.getById(id);
        return AjaxResult.success(tbBusiness);
    }

    /**
     * @description: 删除商机
     * @param: ids
     * @return: com.huike.common.core.domain.AjaxResult
     * @author STJ12138
     * @date: 2023/7/12 22:32
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除商机")
    public AjaxResult delete(@PathVariable List<Long> ids){
        businessService.delete(ids);
        return AjaxResult.success();
    }

    /**
     * @description:  踢回公海
     * @param: id 商机id
               reason 原因
     * @return: com.huike.common.core.domain.AjaxResult
     * @author STJ12138
     * @date: 2023/7/12 23:04
     */
    @PutMapping("/back/{id}/{reason}")
    @ApiOperation("踢回公海")
    public AjaxResult back(@PathVariable Long id,@PathVariable String reason){
        businessService.back(id,reason);
        return AjaxResult.success();
    }

    /**
     * @description: 查询公海池
     * @param: tbBusiness
     * @return: com.huike.common.core.page.TableDataInfo<java.util.List<com.huike.business.domain.TbBusiness>>
     * @author STJ12138
     * @date: 2023/7/12 23:18
     */
    @GetMapping("/pool")
    @ApiOperation("查询公海池")
    public TableDataInfo<List<TbBusiness>> pool(TbBusiness tbBusiness){
        TableDataInfo<List<TbBusiness>> tableDataInfo = businessService.pool(tbBusiness);
        return tableDataInfo;
    }

    /**
     * @description: 批量捞取
     * @param: assignmentVo
     * @return: com.huike.common.core.domain.AjaxResult
     * @author STJ12138
     * @date: 2023/7/13 8:12
     */
    @PutMapping("/gain")
    @ApiOperation("批量捞取")
    public AjaxResult gain(@RequestBody AssignmentVo assignmentVo){
        assignmentVo.setUserId(SecurityUtils.getUserId());
        businessService.assignment(assignmentVo);
        return AjaxResult.success();
    }
}
